#ifndef DISPATCH_H_
#define DISPATCH_H_

#include "pcb_strc.h"
#include "mpx_supt.h"

/* Module R3 */
typedef struct context {
	unsigned int BP, DI, SI, DS, ES;
	unsigned int DX, CX, BX, AX;
	unsigned int IP, CS, FLAGS;
} context;

typedef struct params {
	int op_code;			//Operation code: IDLE, EXIT, READ, WRITE
	int device_id;			//TERMINAL, COM_PORT
	unsigned char *buf_addr;//Buffer address
	int *count_addr;		//Size of the buffer
} params;

/* Module R6 */
//IO Request Descriptor
typedef struct iod_rec {
	char pcb_name[PROC_NAME_LEN];
	pcb_rec *pcb;
	int req_type;
	unsigned char *buf_addr;
	int *buf_cnt;
	struct iod_rec *next;
} iod_rec;

//IO Control Block
typedef struct iocb {
	int event_flag;
	int iod_count;
	struct iod_rec *head;
	struct iod_rec *tail;
} iocb;

int dispatch_init();
void interrupt sys_call();
void interrupt dispatch();
int load_processes();
void load_process(char *filename, int priority, int class);

void test1_R3();
void test2_R3();
void test3_R3();
void test4_R3();
void test5_R3();

int load_comhan_proc();
void open_io();
void close_io();
void scedule_io();
void process_io_req();

#endif /* DISPATCH_H_ */